**************************************************************************************************
*** This do file creates the replication results for 
*** Women’s Economic Rights in Developing Countries and the Gender Gap in Migration to Germany 	*/
*** Thomas Plümper (Vienna University of Economics and Business)																		*/
*** Eric Neumayer (LSE)																			*/
*** 																							*/
*** Published in: IZA Journal of Development and Migration, 2021															*/
**************************************************************************************************
**************************************************************************************************
/* Note: 
You have to change "local DIR" to the directory you copy the original stata files contained 	*/
/* in the zip file and then run the do file. 													*/
**************************************************************************************************

version 12.0
drop _all
clear matrix


capture net install outreg2, from(http://fmwww.bc.edu/RePEc/bocode/o)			/* checks whether outreg2 is installed 		*/


***********************************************************************************
local DIR = "d:\Research\Asylum and Migration"  /*change relative path to the directory where the files are located */
cd "`DIR'"
***********************************************************************************

use "Article for IZA journal (migration).dta", clear


***** Restricted access to productive and financial resources & Discrimination in the family & Restricted physical integrity


tsset


** Generate inter-polated gender discrimination index
capture drop oecd_discr_interpol
bys country: ipolate oecd_discr year, gen(oecd_discr_interpol) 
replace oecd_discr_interpol=. if year<2009

** Revert oecd_discr_interpol, so higher values mean less discrimination
replace oecd_discr_interpol=100-oecd_discr_interpol

tsset


* Table 1

* Random effects
xtreg share_female_entry_nobirths l.share_female_entry_nobirths oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV  ln_distw visanotfree   i.year      if EUmem_MEM==0 & developed_country==0, robust
outreg2 using table1, excel replace  e(r2_o ) dec(3)


* Xtdpdsys
xtdpdsys share_female_entry_nobirths oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV    yeardum59-yeardum68     if EUmem_MEM==0 & developed_country==0    , vce(robust )
outreg2 using table1, excel append  e(r2_o ) dec(3)
estat abond



* Table 2
corr oecd_discr_interpol wbl_index

* Random effects
xtreg share_female_entry_nobirths l.share_female_entry_nobirths wbl_index  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV  ln_distw visanotfree   i.year      if EUmem_MEM==0 & developed_country==0, robust
outreg2 using table2, excel replace e(r2_o ) dec(3)

* Regional fixed effects
xtreg share_female_entry_nobirths l.share_female_entry_nobirths  wbl_index  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV  ln_distw visanotfree   i.year i.id_unsubregion_origin2     if EUmem_MEM==0 & developed_country==0, robust
outreg2 using table2, excel append e(r2_o ) dec(3)


* Table 3

* Random effects
xtreg share_female_entry_nobirths l.share_female_entry_nobirths oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV  ln_distw visanotfree   i.year  v2x_gencs    if EUmem_MEM==0 & developed_country==0, robust
outreg2 using table3, excel replace e(r2_o ) dec(3)


* Xtdpdsys
xtdpdsys share_female_entry_nobirths oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV    v2x_gencs  yeardum59-yeardum68   if EUmem_MEM==0 & developed_country==0    , vce(robust )
outreg2 using table3, excel append e(r2_o ) dec(3)
estat abond


* Random effects
xtreg share_female_entry_nobirths l.share_female_entry_nobirths oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV  ln_distw visanotfree   i.year   v2x_genpp   if EUmem_MEM==0 & developed_country==0, robust
outreg2 using table3, excel append e(r2_o ) dec(3)


* Xtdpdsys
xtdpdsys share_female_entry_nobirths oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV    v2x_genpp  yeardum59-yeardum68   if EUmem_MEM==0 & developed_country==0    , vce(robust )
outreg2 using table3, excel append e(r2_o ) dec(3)
estat abond




* Table 4
capture drop oecd_discr_interpol_sq
gen oecd_discr_interpol_sq=oecd_discr_interpol*oecd_discr_interpol

* Random effects
xtreg share_female_entry_nobirths l.share_female_entry_nobirths oecd_discr_interpol oecd_discr_interpol_sq  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV  ln_distw visanotfree   i.year      if EUmem_MEM==0 & developed_country==0, robust
outreg2 using table4, excel replace e(r2_o ) dec(3)


capture drop lshare_female_entry_nobirths
gen lshare_female_entry_nobirths=l.share_female_entry_nobirths
xtreg share_female_entry_nobirths lshare_female_entry_nobirths c.oecd_discr_interpol##c.oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV  ln_distw visanotfree   i.year      if EUmem_MEM==0 & developed_country==0, robust
margins, dydx(oecd_discr_interpol) at (oecd_discr_interpol=(22 (1) 92))
marginsplot

* Xtdpdsys

xtdpdsys share_female_entry_nobirths oecd_discr_interpol oecd_discr_interpol_sq  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV     yeardum59-yeardum68    if EUmem_MEM==0 & developed_country==0    , vce(robust )
outreg2 using table4, excel append e(r2_o ) dec(3)
estat abond



capture drop gdppc_wdi_pw_sq
gen gdppc_wdi_pw_sq=gdppc_wdi_pw*gdppc_wdi_pw


* Random effects
xtreg share_female_entry_nobirths l.share_female_entry_nobirths oecd_discr_interpol  gdppc_wdi_pw gdppc_wdi_pw_sq  growth_wdi_pw polity2_p4 allwar_dummy_PV  ln_distw visanotfree   i.year      if EUmem_MEM==0 & developed_country==0, robust
outreg2 using table4, excel append e(r2_o ) dec(3)



* Xtdpdsys
xtdpdsys share_female_entry_nobirths oecd_discr_interpol   gdppc_wdi_pw gdppc_wdi_pw_sq  growth_wdi_pw polity2_p4 allwar_dummy_PV    yeardum59-yeardum68     if EUmem_MEM==0 & developed_country==0    , vce(robust )
outreg2 using table4, excel append e(r2_o ) dec(3)
estat abond





* Table 5
* Random effects
xtreg share_female_entry_nobirths l.share_female_entry_nobirths oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV  ln_distw visanotfree   i.year      if EUmem_MEM==0 & developed_country==0 & total_entry_nobirths>=250, robust 
outreg2 using table5, excel replace e(r2_o ) dec(3)



* Xtdpdsys
xtdpdsys share_female_entry_nobirths oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV   yeardum59-yeardum68      if EUmem_MEM==0 & developed_country==0   & total_entry_nobirths>=250  , vce(robust )
outreg2 using table5, excel append e(r2_o ) dec(3)
estat abond



* Random effects
xtreg share_female_entry_nobirths l.share_female_entry_nobirths oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV  ln_distw visanotfree   i.year      if EUmem_MEM==0 & developed_country==0 & total_entry_nobirths>=500, robust 
outreg2 using table5, excel append e(r2_o ) dec(3)


* Xtdpdsys
xtdpdsys share_female_entry_nobirths oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV     yeardum59-yeardum68    if EUmem_MEM==0 & developed_country==0   & total_entry_nobirths>=500  , vce(robust )
outreg2 using table5, excel append e(r2_o ) dec(3)
estat abond



use "Article for IZA journal (migration).dta", clear

tsset


** Generate inter-polated gender discrimination index
capture drop oecd_discr_interpol
bys country: ipolate oecd_discr year, gen(oecd_discr_interpol) 
replace oecd_discr_interpol=. if year<2009

** Revert oecd_discr_interpol, so higher values mean less discrimination
replace oecd_discr_interpol=100-oecd_discr_interpol


* Annex 1
keep if year>=2009
keep if year<=2018
keep if EUmem_MEM==0 & developed_country==0
tsset
quietly xtreg share_female_entry_nobirths l.share_female_entry_nobirths oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV  ln_distw visanotfree   i.year      if EUmem_MEM==0 & developed_country==0, robust
capture drop esample
gen esample=e(sample)
collapse (sum) f_entry_nobirths m_entry_nobirths t_entry_nobirth esample, by(country)
gen  share_female_entry_nobirths=f_entry_nobirths/t_entry_nobirth*100
drop if t_entry_nobirth<1000
drop if esample==0
drop f_entry_nobirths m_entry_nobirths
gsort -share_female_entry_nobirths


use "Article for IZA journal (migration).dta", clear

tsset


** Generate inter-polated gender discrimination index
capture drop oecd_discr_interpol
bys country: ipolate oecd_discr year, gen(oecd_discr_interpol) 
replace oecd_discr_interpol=. if year<2009

** Revert oecd_discr_interpol, so higher values mean less discrimination
replace oecd_discr_interpol=100-oecd_discr_interpol

tsset

* Annex 4
xtreg share_female_entry_nobirths l.share_female_entry_nobirths oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV  ln_distw visanotfree   i.year      if EUmem_MEM==0 & developed_country==0, robust
sum share_female_entry_nobirths l.share_female_entry_nobirths oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV  ln_distw visanotfree      if e(sample)

quietly xtreg share_female_entry_nobirths l.share_female_entry_nobirths wbl_index  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV  ln_distw visanotfree   i.year      if EUmem_MEM==0 & developed_country==0, robust
sum wbl_index if e(sample)

quietly xtreg share_female_entry_nobirths l.share_female_entry_nobirths oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV  ln_distw visanotfree v2x_gencs v2x_genpp    i.year      if EUmem_MEM==0 & developed_country==0, robust
sum v2x_gencs v2x_genpp    if e(sample)

* Correlation info
corr wbl_index     polity2_p4   gdppc_wdi_pw growth_wdi_pw   allwar_dummy_PV  ln_distw visanotfree   v2x_gencs v2x_genpp   if e(sample)

* Annex 5
xtreg share_female_entry_nobirths l.share_female_entry_nobirths oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV  ln_distw visanotfree   i.year      if EUmem_MEM==0 & developed_country==0, robust
keep if e(sample)
collapse year, by(country)

* Annex 6
use "Article for IZA journal (migration).dta", clear

tsset


** Generate inter-polated gender discrimination index
capture drop oecd_discr_interpol
bys country: ipolate oecd_discr year, gen(oecd_discr_interpol) 
replace oecd_discr_interpol=. if year<2009

** Revert oecd_discr_interpol, so higher values mean less discrimination
replace oecd_discr_interpol=100-oecd_discr_interpol

tsset


* Explanatory variables pre-determined
xtdpdsys share_female_entry_nobirths    yeardum59-yeardum68     if EUmem_MEM==0 & developed_country==0    , pre(oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV ) vce(robust )
outreg2 using tablea6, excel replace  e(r2_o ) dec(3)
estat abond


* Explanatory variables endogenous 
xtdpdsys share_female_entry_nobirths    yeardum59-yeardum68     if EUmem_MEM==0 & developed_country==0    , end(oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV ) vce(robust ) 
outreg2 using tablea6, excel append  e(r2_o ) dec(3)
estat abond


* Explanatory variables pre-determined & maximum of 2 lags used
xtdpdsys share_female_entry_nobirths    yeardum59-yeardum68     if EUmem_MEM==0 & developed_country==0    , pre(oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV ) vce(robust ) maxlag(2)
outreg2 using tablea6, excel append  e(r2_o ) dec(3)
estat abond


* Explanatory variables endogenous & maximum of 2 lags used
xtdpdsys share_female_entry_nobirths    yeardum59-yeardum68     if EUmem_MEM==0 & developed_country==0    , end(oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV ) vce(robust )  maxlag(2)
outreg2 using tablea6, excel append  e(r2_o ) dec(3)
estat abond


* Explanatory variables pre-determined & maximum of 2 lags used, including LDV
xtdpdsys share_female_entry_nobirths    yeardum59-yeardum68     if EUmem_MEM==0 & developed_country==0    , pre(oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV ) vce(robust ) maxldep(2) maxlag(2)
outreg2 using tablea6, excel append  e(r2_o ) dec(3)
estat abond


* Explanatory variables endogenous & maximum of 2 lags used, including LDV
xtdpdsys share_female_entry_nobirths    yeardum59-yeardum68     if EUmem_MEM==0 & developed_country==0    , end(oecd_discr_interpol  gdppc_wdi_pw growth_wdi_pw  polity2_p4 allwar_dummy_PV ) vce(robust ) maxldep(2) maxlag(2)
outreg2 using tablea6, excel append  e(r2_o ) dec(3)
estat abond



